package jdbc;

import jdbc.common.InputUtil;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Scanner;

public class RegUserDemo {
    public static void main(String[] args) throws  Exception{
        DBUtil dbUtil=new DBUtil();
        Connection connection=dbUtil.getconnection();
        Statement statement=connection.createStatement();
        UserInfo userinfo= InputUtil.getInputObject(new UserInfo(),"欢迎注册");
        System.out.println(userinfo);
//        Scanner scanner=new Scanner(System.in);
//        System.out.println("请输入用户名：");
//        String username=scanner.next();
//        System.out.println("请输入密码：");
//        String password=scanner.next();
//        System.out.println("请输入昵称：");
//        String nickname=scanner.next();
//        System.out.println("请输入年龄：");
//        int age=scanner.nextInt();
        String sql="INSERT INTO userinfo (username,password,nickname,age) VALUES ('"+userinfo.getUsername()+"','"+userinfo.getPassword()+"','"+userinfo.getNickname()+"','"+userinfo.getAge()+"')" ;

        int num=statement.executeUpdate(sql);
        System.out.println(num>0?"添加成功！":"添加失败！");
        System.out.println(num+"行数据受影响！");
    }
}
